from flask import Blueprint, render_template
import os
from app.config import Config

main_bp = Blueprint('main', __name__)


@main_bp.route('/')
def index():
    """主页"""
    # 获取模型状态
    model_exists = os.path.exists(os.path.join(Config.MODEL_FOLDER, 'model.pth'))

    # 获取数据集状态
    datasets = []
    if os.path.exists(Config.DATA_FOLDER):
        for file in os.listdir(Config.DATA_FOLDER):
            if file.endswith(('.csv', '.xlsx', '.xls')):
                datasets.append(file)

    return render_template('index.html',
                           model_exists=model_exists,
                           datasets=datasets)
